﻿package game.managers
{
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.InteractiveObject;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.utils.Dictionary;
	
	import game.UIComponent.Panel;
	import game.controller.GameDispatcher;

	/**
	 * 弹出窗口管理
	 * @author xiezhicheng
	 */
	public class PopManage
	{
		//private var _myPopList:Dictionary=new Dictionary(); //默认坐标
		//private var _onPopList:Dictionary=new Dictionary(); //记寻弹出窗
		public static var layer:Sprite;
		private var _dispatcher:GameDispatcher;
		private static var _instance:PopManage;

		public function PopManage()
		{
			if (_instance)
			{
				throw new Error("PopUpManager is a single class");

			}
			else
			{
				_instance=this;
				_dispatcher=GameDispatcher.getInstance();
				layer = LayerManager.windowLayer;
			}
		}


		public static function getInstance():PopManage
		{
			if (_instance == null)
			{
				_instance=new PopManage();
			}
			return _instance;
		}

	/**
	 * 弹出
	 * @param popCon
	 *
	 */
		public function popUp(popCon:Panel):void{
			layer.addChild(popCon);
		}


	/**
	 * 弹回
	 * @param popCon
	 *
	 */
		public function popBack(popCon:Panel):void
		{
			if (layer.contains(popCon) == true){
				layer.removeChild(popCon);
			}
			
		}


	/**
	 * 判断是否处于最顶层
	 * @param popCon
	 *
	 */
		public function isTop(popCon:Panel):Boolean
		{
			if (layer.contains(popCon) == true && layer.getChildIndex(popCon) < layer.numChildren - 1)
				return false;
			else
				return true;
		}


	/**
	 * 深度设置成最顶层
	 * @param popCon
	 *
	 */
		public function swapTop(popCon:Panel):void
		{
			if (layer.contains(popCon) == true){
				layer.removeChild(popCon);
			}
			layer.addChild(popCon);
		}


	/**
	 * 删除最顶层的弹出窗口
	 *
	 */
		private function removeTopChild():void
		{
			if (layer.numChildren == 0)
			{
				return;
			}
			(layer.getChildAt(layer.numChildren - 1) as Panel).isPop=false;
		}


	}
}